package com.pmpd.activity.controller.api;

import com.dmap.base.constants.Constant;
import com.dmap.base.vo.BaseVo;
import com.pmpd.activity.annotation.LimitRequest;
import com.pmpd.activity.po.HotActivity;
import com.pmpd.activity.service.api.ApiHotActivityService;
import com.pmpd.activity.vo.api.ApiHotActivityVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * \* User: helei
 * \* Date: 18/05/18
 * \* Description:
 * \
 */
@Api(value = "App/热门活动API", description = "App/热门活动API")
@RestController
@RequestMapping(value = "/api/pmpd-activity-server/v1/activity/hotActivity")
public class ApiHotActivityController {
    @Resource
    private ApiHotActivityService apiHotActivityService;

    @ResponseBody
    @ApiOperation(value = "根据app编号查询热门活动",
            notes = "1. 必填： projectId;" +
                    "2. 最多返回5条;")

    @ApiImplicitParams({@ApiImplicitParam(name = "language", value = "language", required = true, dataType = "String", paramType = "header"),
            @ApiImplicitParam(name = "userId", value = "userId", required = true, dataType = "String", paramType = "header")
    })
    @RequestMapping(value = "/select/selectByProjectId", method = RequestMethod.GET)
    public BaseVo selectByProjectId(@RequestParam String projectId, HttpServletRequest request) {
        BaseVo baseVo = new BaseVo();
        if (StringUtils.isBlank(projectId)) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return baseVo;
        }
        String language = request.getHeader("language");
        if (StringUtils.isBlank(language)) {
            language = "ZH_CN";
        }
        List<HotActivity> list = apiHotActivityService.selectByProjectId(projectId, language);
        List<ApiHotActivityVo> voList = new ArrayList<>();
        list.forEach(hotActivity ->
                voList.add(new ApiHotActivityVo(hotActivity))
        );
        baseVo.setData(voList);
        return baseVo;
    }

}